const fs=require('fs');
var globalData='';
var cnt=0;
var rds =fs.createReadStream('input.txt');

 var wrs =fs.createWriteStream('data.txt');
 

rds.on('data',function(trunk){
    cnt++;
    console.log('第'+cnt +'次读取，共'+byteLength(trunk)+'字节。');
    globalData+=trunk;
    // console.log(trunk); 
    wrs.write(globalData);
 });
 rds.on('end',function(trunk){
    console.log("读取文件已完成！");
     wrs.end();
 });
 rds.on('close',function(){
    console.log("文件已关闭！");
    console.log(globalData);
 });
 rds.on('open',function(trunk){
    console.log("文件已打开");
 });
 rds.on('error',function(err){
    console.log(err);
 });


 wrs.on('finish',function(){
    console.log('写入完成！');
});

wrs.on('error',function(err){
    console.log(err);
});
wrs.on('close',function(){
    console.log('写文件已关闭！');
})